<template>
  <fieldset>
    <legend>登入页</legend>
    用户名:
    <input type="text" v-model="username" />
    <br />
    密码：
    <input type="password" v-model="password" @keydown.enter="login" />
    <br />
    <button @click="login">登录</button>
  </fieldset>
</template>
<script setup>
import * as api from "../../api/users";
import { ref } from "vue";
import { useRouter } from "vue-router";
let username = ref("");
let password = ref("");
let router = useRouter();
//发送登录请求
let login = async () => {
  let res = await api.loginApi(username.value, password.value);
  console.log(res);
  //如果登录成功，保存返回结果中的令牌token
  if (res.data.state) {
    sessionStorage.setItem("qf-token", res.data.token);
    router.push("/");
  } else {
    alert(res.data.msg);
  }
};
</script>
<style scoped></style>
